<?php
class Video_model extends CI_Model {
    function __construct()
    {
        parent::__construct();
    }
    //Xóa video
    function xoa($id)
    {
        $this->db->where('id_video',$id);
        $result=$this->db->delete('video');
        return $result;
    }
    //Duyệt video lên
    function duyetlen($id,$trangthai)
    {
        $this->db->where('id_video',$id);
        $result=$this->db->update('video',array('trangthai_video'=>$trangthai));
        return $result;
    }
    //Xem video theo chuyen muc $chuyenmuc="all" nếu muốn chọn tất
    function xemvideo($id,$chuyenmuc)
    {
        if($chuyemuc="all")
            {
                $this->db->where('id_video',$id);
                $result=$this->db->get('video');
                return $result->result_array();
            }else 
                {
                    $this->db->where('id_video',$id);
                    $this->db->where('chuyenmuc',$chuyenmuc);
                    $result=$this->db->get('video');
                    return $result->result_array();
                }
    }
    function thongtinVideo($id)
    {
        $this->db->where('id_video',$id);
        $result=$this->db->get('video');
        return $result->result_array();
    }
    //Sửa tinbai
    function suavideo($id,$nguoisua,$tennguoisua,$tieude,$tomtat,$noidung,$chuyenmuc,$thumbnail,$trangthai,$ngonngu)
    {
        $data=array(
        'tieude_video'=>$tieude,
        'tomtat_video'=>$tomtat,
        'noidung_video'=>$noidung,
        'chuyenmuc'=>$chuyenmuc,
        'thumbnail_video'=>$thumbnail,
        'nguoidung_last'=>$nguoisua,
        'ten_nguoidung_last'=>$tennguoisua,
        'trangthai_video'=>$trangthai,
        'ngonngu'=>$ngonngu,
        'datetime_last'=>date("Y-m-d H:i:s")
        );
         $this->db->where('id_video',$id);
         $result=$this->db->update('video',$data);
         return $result;
         
    }
    //Tạo tin bài id_marked =null khi tao video goc
    function taovideo($id_mark,$ngonngu,$nguoitao,$ten_nguoitao,$tieude,$tomtat,$noidung,$chuyenmuc,$thumbnail,$trangthai)
    {
        date_default_timezone_set('Asia/Ho_Chi_Minh');
        $data=array(
        'id_mark'=>$id_mark,
        'ngonngu'=>$ngonngu,
        'tieude_video'=>$tieude,
        'tomtat_video'=>$tomtat,
        'noidung_video'=>$noidung,
        'chuyenmuc'=>$chuyenmuc,
        'thumbnail_video'=>$thumbnail,
        'nguoidung_first'=>$nguoitao,
        'ten_nguoidung_first'=>$ten_nguoitao,
        'trangthai_video'=>$trangthai,
        'datetime_first'=>date("Y-m-d H:i:s")
        );
         $result=$this->db->insert('video',$data);
         return $this->db->insert_id();   
         
    } 
}
?>